using System.Collections.Generic;
using System.Drawing;

namespace LeanUi.ImageBundle
{
    public class ImageMerger
    {
        private readonly IArrangingStrategy _arrangingStrategy;

        public ImageMerger(IArrangingStrategy arrangingStrategy)
        {
            _arrangingStrategy = arrangingStrategy;

        }

        public Bitmap DrawBundledImage( IList<ImageRect> imageRects )
        {
            Size size = _arrangingStrategy.ArrangeImages(imageRects);
            Bitmap bundledImage = new Bitmap(size.Width, size.Height);
            using (Graphics g2d = Graphics.FromImage(bundledImage))
            {
                foreach (ImageRect imageRect in imageRects)
                {
                    g2d.DrawImage(imageRect.Image, imageRect.Left, imageRect.Top, imageRect.Width, imageRect.Height);
                }
            }
            return bundledImage;
        }
    }
}